package trial.bishi2022;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @创建人 MBY381
 * @创建时间 2022/4/9 14:37
 * @描述 这两题就tm离谱，正式招聘也这难度就好了
 */
public class ChinaMerchantsBankCo {
    /**
     * @param args
     */
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int len = str.length();
        StringBuilder sb1 = new StringBuilder(str.substring(0, len / 2));
        StringBuilder sb2 = new StringBuilder(str.substring(len / 2, len));
        sb1.reverse();
        sb2.reverse();
        System.out.println(sb1.append(sb2).toString());
    }

    public static void main(String[] args) {
        int n = 0;
        ArrayList<Student> li = new ArrayList<>();
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            n = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            Student stu = new Student();
            String name = null;
            int c, m, e;
            name = sc.next();
            c = sc.nextInt();
            m = sc.nextInt();
            e = sc.nextInt();
            stu.setName(name);
            stu.setCHN(c);
            stu.setMath(m);
            stu.setEnglish(e);
            li.add(stu);
        }
        ArrayList<Integer> cMaxTag = new ArrayList<>();
        ArrayList<Integer> mMaxTag = new ArrayList<>();
        ArrayList<Integer> eMaxTag = new ArrayList<>();
        int maxc = 0, maxm = 0, maxe = 0;
        for (int i = 0; i < li.size(); i++) {
            int c = li.get(i).getCHN();
            int m = li.get(i).getMath();
            int e = li.get(i).getEnglish();
            maxc = cmp(maxc, c, cMaxTag, i);
            maxm = cmp(maxm, m, mMaxTag, i);
            maxe = cmp(maxe, e, eMaxTag, i);
        }
        printResult(li, cMaxTag);
        System.out.print("\n");
        printResult(li, mMaxTag);
        System.out.print("\n");
        printResult(li, eMaxTag);
    }

    /**
     * 最大值
     *
     * @param max
     * @param score
     * @param li
     * @param tag
     * @return
     */
    public static int cmp(int max, int score, ArrayList<Integer> li, int tag) {
//        System.out.println("score:"+score+"max:"+max);
        if (score > max) {
            max = score;
            li.clear();
            li.add(tag);
        } else if (score == max) {
            li.add(tag);
        }
        return max;
    }


    /**
     * @param li     数据库
     * @param maxTag 最大成绩位置tag库
     */
    public static void printResult(ArrayList<Student> li, ArrayList<Integer> maxTag) {
        ArrayList<String> strArr = new ArrayList<>();
        for (int i = 0; i < maxTag.size(); i++) {
            strArr.add(li.get(maxTag.get(i)).getName());
        }

        sort(strArr);
        int tagOfPrint = 0, size = strArr.size();
        while (size > 0 && tagOfPrint < size) {
            System.out.print(strArr.get(tagOfPrint) + " ");
            tagOfPrint++;
        }
    }

    /**
     * //直接字符串数字排序就可以的，傻杯了
     *
     * @param strArr
     */
    public static void sort(ArrayList<String> strArr) {
        int[] charInt = new int[strArr.size()];
        for (int j = 0; j < strArr.size() - 1; j++) {
            for (int i = 0; i < strArr.size() - 1; i++) {
                String s1 = strArr.get(i);
                String s2 = strArr.get(i + 1);
                if (s1.compareTo(s2) > 0) {
                    strArr.remove(i);
                    strArr.add(i, s2);
                    strArr.remove(i + 1);
                    strArr.add(i + 1, s1);
                }
            }
        }
    }


    /**
     * 包装类
     */
    static class Student {
        private String name;
        private int CHN;
        private int math;
        private int english;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getCHN() {
            return CHN;
        }

        public void setCHN(int CHN) {
            this.CHN = CHN;
        }

        public int getMath() {
            return math;
        }

        public void setMath(int math) {
            this.math = math;
        }

        public int getEnglish() {
            return english;
        }

        public void setEnglish(int english) {
            this.english = english;
        }
    }
}
